﻿using System.Data;
using System.Data.SqlClient;

namespace MyWeb.Data
{
    public class ProductController : SqlDataProvider
    {
        #region [Product_GetByAll]

        public DataTable Product_GetByAll()
        {
            return GetDataTable("sp_Product_GetByAll");
        }

        #endregion

        #region [Product_GetById]

        public DataTable Product_GetById(string id)
        {
            var p1 = new SqlParameter("@id", id);
            return GetDataTable("sp_Product_GetById", p1);
        }

        #endregion

        #region [Product_Insert]

        public void Product_Insert(ProductInfo product)
        {
            var p0 = new SqlParameter("@id", product.Id);
            var p1 = new SqlParameter("@name", product.Name);
            var p2 = new SqlParameter("@detail", product.Detail);
            var p3 = new SqlParameter("@price", product.Price);
            var p4 = new SqlParameter("@image", product.Image);
            var p5 = new SqlParameter("@pricenew", product.PriceNew);
            var p6 = new SqlParameter("@date", product.Date);
            var p7 = new SqlParameter("@order", product.Order);
            var p8 = new SqlParameter("@status", product.Status);
            var p9 = new SqlParameter("@GroupProduct_Id", product.GroupProduct_Id);
            var p10 = new SqlParameter("@Distribution_Id", product.Distribution_Id);
            ExecuteStoreProcedure("sp_Product_Insert",p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
        }

        #endregion

        #region [Product_Update]

        public void Product_Update(ProductInfo product)
        {
            var p0 = new SqlParameter("@id", product.Id);
            var p1 = new SqlParameter("@name", product.Name);
            var p2 = new SqlParameter("@detail", product.Detail);
            var p3 = new SqlParameter("@price", product.Price);
            var p4 = new SqlParameter("@image", product.Image);
            var p5 = new SqlParameter("@pricenew", product.PriceNew);
            var p6 = new SqlParameter("@date", product.Date);
            var p7 = new SqlParameter("@order", product.Order);
            var p8 = new SqlParameter("@status", product.Status);
            var p9 = new SqlParameter("@GroupProduct_Id", product.GroupProduct_Id);
            var p10 = new SqlParameter("@Distribution_Id", product.Distribution_Id);
            ExecuteStoreProcedure("sp_Product_Update", p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
        }

        #endregion

        #region [Product_Delete]

        public void Product_Delete(string id)
        {
            var p0 = new SqlParameter("@id", id);
            ExecuteStoreProcedure("sp_Product_Delete", p0);
        }

        #endregion

        #region [Product_GetByGroupProductId]

        public DataTable Product_GetByGroupProductId(int GroupProductId)
        {
            var p1 = new SqlParameter("@GroupProduct_Id", GroupProductId);
            return GetDataTable("[sp_Product_GetByGroupProductId]", p1);
        }

        #endregion

        #region [Product_ActiveStatus]

        public void Product_ActiveStatus(string id, int status)
        {
            var p1 = new SqlParameter("@id", id);
            var p2 = new SqlParameter("@status", status);
            ExecuteStoreProcedure("sp_Product_ActiveStatus", p1, p2);
        }

        #endregion

        #region [Product_SelectTop]

        public DataTable Product_SelectTop(string sql)
        {
            return GetTable(sql);
        }

        #endregion
    }
}